package top.lyjwn.todo.common.utils;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import jakarta.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 微信支付回调
 * 
 * @author luoyujie
 *
 */
public class WXNotify {

	private final static Logger logg = LoggerFactory.getLogger(WXNotify.class);

	public static String getString(HttpServletRequest request) {
		String xmlStr = "";
		try {
			InputStream inStream = request.getInputStream();
			int _buffer_size = 1024;
			if (inStream != null) {
				ByteArrayOutputStream outStream = new ByteArrayOutputStream();
				byte[] tempBytes = new byte[_buffer_size];
				int count = -1;
				while ((count = inStream.read(tempBytes, 0, _buffer_size)) != -1) {
					outStream.write(tempBytes, 0, count);
				}
				tempBytes = null;
				outStream.flush();
				outStream.close();
				// 将流转换成字符串
				xmlStr = new String(outStream.toByteArray(), "UTF-8");
				return xmlStr;
			}
			// 通知微信支付系统接收到信息
		} catch (IOException e) {
			logg.error(e.getMessage());
			e.printStackTrace();
		}
		return null;
	}
}
